/* 时间 */
define(function(require, exports) {
	        require("component/js/moment.min.js");
			require('component/js/jquery.daterangepicker.js');
			$(".statisticsReportData").each(function() {
				$(this).click(function() {
					var myDate = new Date();
					var startDate = myDate;
					var endDate = myDate;
					if ($(this).attr('id') == 'statisticsReportData1') {
						startDate = new Date(Date.parse(myDate)
								+ (86400000 * -29));
						endDate = new Date(Date.parse(myDate));
								//+ (86400000 * -1));;
						makeDate(formatDate(startDate), formatDate(endDate));
					}
					if ($(this).attr('id') == 'statisticsReportData2') {
						startDate = new Date(Date.parse(myDate)
								+ (86400000 * -6));
						endDate = new Date(Date.parse(myDate));
								//+ (86400000 * -1));;
						makeDate(formatDate(startDate), formatDate(endDate));
					}
					if ($(this).attr('id') == 'statisticsReportData3') {

						var year = myDate.getFullYear();
						var month = myDate.getMonth();
						var endDate = new Date(year, month, 1);
						endDate = new Date(Date.parse(endDate)
								+ (86400000 * -1));
						month -= 1;
						if (month == 0) {
							year -= 1;
							month = 12;
						}
						var startDate = new Date(year, month, 1);
						makeDate(formatDate(startDate), formatDate(endDate));

					}
					if ($(this).attr('id') == 'statisticsReportData4') {

						startDate = new Date(Date.parse(myDate)
								+ (86400000 * -(myDate.getDay() + 6)));
						endDate = new Date(Date.parse(myDate)
								+ (86400000 * -myDate.getDay()));
						makeDate(formatDate(startDate), formatDate(endDate));

					}
					if ($(this).attr('id') == 'statisticsReportData5') {
						startDate = new Date(Date.parse(myDate)
								+ (86400000 * -1));
						endDate = startDate;
						makeDate(formatDate(startDate), formatDate(endDate));

					}
					if ($(this).attr('id') == 'statisticsReportData6') {
						makeDate(formatDate(myDate), formatDate(myDate));

					}

				});
			});
			function makeDate(startDate, endDate) {
				$("#startDate").val(startDate);
				$("#endDate").val(endDate);
				$('#datePicker').data('dateRangePicker').setDateRange(startDate,endDate);
			}
			function formatDate(date) {
				var str = '';
				str += date.getFullYear() + '-';
				str += (date.getMonth() + 1) > 9 ? (date.getMonth() + 1)
						.toString() : '0' + (date.getMonth() + 1);
				str +='-';
				str += date.getDate() > 9 ? date.getDate().toString() : '0'
						+ date.getDate();
				return str;
			}
			
			$('#datePicker').dateRangePicker({
		    	separator : ' 至 ',
		    	language:'cn'
		    }).bind('datepicker-apply',function(event,obj){
		    	$("#startDate").val(obj.date1.Format("yyyy-MM-dd"));
		    	$("#endDate").val(obj.date2.Format("yyyy-MM-dd"));
		    	// 需要清一下错误提示
		    	$("#datePicker").parent().find('.error').hide();
		    });
			
			$('#clearTime').click(function() {
				$("#startDate").val('');
				$("#endDate").val('');
				$('#datePicker').data('dateRangePicker').clear();
			})
		});